const { where } = require('sequelize')
const usermodle = require('../../modle/user')
const hosemodle = require('../../modle/hose')
const lookhismodle = require('../../modle/lookhis')
const userlovemodle = require('../../modle/userlove')
const unlinedatamodle = require('../../modle/unlinedata')

module.exports = {
    async zc(data) {
        const rudata = await usermodle.create(data)
        return rudata
    },
    async ishas(data) {
        const rudata = await usermodle.findOne({
            where: { ...data }
        })
        return rudata
    },
    async update(id, img) {
        return await usermodle.update({ img }, {
            where: { id }
        })
    },
    async updatename(id, name) {
        return await usermodle.update({ name }, {
            where: { id }
        })
    },
    async modulebaibai(id) {
        await usermodle.destroy({
            where: { id }
        })
        await hosemodle.destroy({
            where: { userid: id }
        })
        await lookhismodle.destroy({
            where: { userid: id }
        })
        await userlovemodle.destroy({
            where: { userid: id }
        })
        return "ok"
    },
    async unlinedata(id) {
        const rudata = await unlinedatamodle.findAll({
            where: { shou: id }
        })
        if (rudata.length > 0) {
            rudata.forEach(async e => {
                await unlinedatamodle.destroy({
                    where: { id: e.id }
                })
            })
        }
        return rudata
    }
}